

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IOUtils;
import org.apache.log4j.BasicConfigurator;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;

/**
 * 创建时间：2018-09-09
 * <p>修改时间：2018-09-09
 * <p>类说明：
 *
 * @author peng
 * @version 1.0
 */
public class FileCopy {
    public static void main(String[] args) throws Exception {
        System.setProperty("hadoop.home.dir", "/usr/local/Cellar/hadoop/3.1.1/libexec");

        if (args.length != 2) {
            System.err.println("Usage: FileCopy <source> <target>");
            System.exit(2);
        }
        BasicConfigurator.configure();
        Configuration conf = new Configuration();

        InputStream in = new BufferedInputStream(new FileInputStream(args[0]));
        FileSystem fs = FileSystem.get(URI.create(args[1]), conf);
        OutputStream out = fs.create(new Path(args[1]));
        IOUtils.copyBytes(in, out, 4094, true);
    }
}
